//
//  U9ForumManager.m
//  U9WatchGame
//
//  Created by uuu9 on 2018/7/23.
//  Copyright © 2018年 UUU9. All rights reserved.
//

#import "U9ForumManager.h"
#import "U9MessageListModel.h"
#import "U9PostListModel.h"
#import "U9PostDetailModel.h"
#import "U9ForumCategoryModel.h"
#import "U9MessageCommonModel.h"
#import "U9MyFolMessageListModel.h"

@implementation U9ForumManager

//回复帖子
+ (void)replyingPostWithUserid:(NSString *)userid andSession:(NSString *)session andPostID:(NSString *)postID andContent:(NSString *)content andParentID:(NSString *)parentID andGameID:(NSString *)gID andCompletionHandle:(void (^)(U9MessageListModel *model, NSError *error))complete{
    NSString *param = [NSString stringWithFormat:@"object_id=%@&parent_id=%@&content=%@&gid=%@&userid=%@&sessionid=%@",postID,parentID,content,gID,userid,session];
    [self POSTBase64:[NSString stringWithFormat:@"%@%@",Api_URL,kReplyToPost]
    parameters:param
completionHandler:^(id responseObj, NSError *error) {
        U9MessageListModel *model = [U9MessageListModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:@"error"];
        }
        complete(model,error);
    }];
}

//获取帖子回复
+(void)getPostReplyListWithPostID:(NSString *)postID andPage:(NSString *)p andCompletionHandle:(void (^)(U9MessageListModel *model, NSError *error))complete{
//    NSString *param = [NSString stringWithFormat:@"object_id=%@&page=%@",postID,p];
     NSString *param = [NSString stringWithFormat:@"object_id=%@",postID];
    [self POSTBase64:[NSString stringWithFormat:@"%@%@",Api_URL,kGetPostReplyList]
    parameters:param
completionHandler:^(id responseObj, NSError *error) {
        U9MessageListModel *model = [U9MessageListModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:@"error"];
        }
        complete(model,error);
    }];
}

//获取回复的回复
+(void)getCommentReplyListWithPostID:(NSString *)postID andReplyID:(NSString *)replyID andPage:(NSString *)p andCompletionHandle:(void (^)(U9MessageListModel *model, NSError *error))complete{
     NSString *param = [NSString stringWithFormat:@"object_id=%@&comment_id=%@&page=%@",postID,replyID,p];
    [self POSTBase64:[NSString stringWithFormat:@"%@%@",Api_URL,kGetReplyReplyList]
    parameters:param
completionHandler:^(id responseObj, NSError *error) {
        U9MessageListModel *model = [U9MessageListModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:@"error"];
        }
        complete(model,error);
    }];
}

//获取帖子列表
+ (void)getPostListWithUserid:(NSString *)userid andSession:(NSString *)session andGameID:(NSString *)gid andPageNum:(NSString *)page andCompletionHandle:(void (^)(U9PostListModel *model, NSError *error))complete{
    NSString *param = [NSString stringWithFormat:@"userid=%@&sessionid=%@",userid,session];
    [self POST:[NSString stringWithFormat:@"%@%@?num=15&gid=%@&page=%@",Api_URL,kGetPostList,gid,page]
    parameters:param
completionHandler:^(id responseObj, NSError *error) {
        U9PostListModel *model = [U9PostListModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
           
        }
        complete(model,error);
    }];
}

//获取帖子详情
+ (void)getPostDetailWithUserid:(NSString *)userid andSession:(NSString *)session andPostID:(NSString *)postID andCompletionHandle:(void (^)(U9PostDetailModel *model, NSError *error))complete{
    NSString *param = [NSString stringWithFormat:@"userid=%@&sessionid=%@&id=%@",userid,session,postID];
    [self POSTBase64:[NSString stringWithFormat:@"%@%@",Api_URL,kGetPostDetail]
           parameters:param
    completionHandler:^(id responseObj, NSError *error) {
        U9PostDetailModel *model = [U9PostDetailModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
}

//获取我的帖子列表
+(void)getMyPostListWithUserid:(NSString *)userid andSession:(NSString *)session andPageNum:(NSString *)page andCompletionHandle:(void (^)(U9PostListModel *model, NSError *error))complete{
    NSString *param = [NSString stringWithFormat:@"userid=%@&sessionid=%@",userid,session];
    [self POSTBase64:[NSString stringWithFormat:@"%@%@?page=%@",Api_URL,kGetMyPostList,page]
           parameters:param
    completionHandler:^(id responseObj, NSError *error) {
        U9PostListModel *model = [U9PostListModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
          complete(model,error);
    }];
}


//
//发布帖子
+ (void)postingPostWithUserid:(NSString *)userid andSession:(NSString *)session andContent:(NSString *)content andTitle:(NSString *)title andGameID:(NSString *)gID andImage:(NSString *)image andCompletionHandle:(void (^)(U9PostListModel *model, NSError *error))complete{
    NSString *param = [NSString stringWithFormat:@"userid=%@&sessionid=%@&gid=%@&title=%@&content=%@&image=%@",userid,session,gID,title,content,image];
    [self POSTBase64:[NSString stringWithFormat:@"%@%@",Api_URL,kPostingPost]
   parameters:param
completionHandler:^(id responseObj, NSError *error) {
        U9PostListModel *model = [U9PostListModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
}


//获取我的帖子回复
+ (void)getMyPostReplyListWithUserid:(NSString *)userid andSession:(NSString *)session andPageNum:(NSString *)page andCompletionHandle:(void (^)(U9MyFolMessageListModel *model, NSError *error))complete{
    NSString *param = [NSString stringWithFormat:@"userid=%@&sessionid=%@",userid,session];
    [self POSTBase64:[NSString stringWithFormat:@"%@%@?page=%@",Api_URL,kGetMyPostReply,page]
   parameters:param
completionHandler:^(id responseObj, NSError *error) {
        U9MyFolMessageListModel *model = [U9MyFolMessageListModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
}

//发帖前获取发帖的游戏分类
+ (void)getGameCatagoryWithUserid:(NSString *)userid andSession:(NSString *)session andGameID:(NSString *)gID andCompletionHandle:(void (^)(U9ForumCategoryModel *model, NSError *error))complete{
    NSString *param = [NSString stringWithFormat:@"userid=%@&sessionid=%@",userid,session];
    [self POST:[NSString stringWithFormat:@"%@%@?gid=%@",Api_URL,kGetCurrentForumClass,gID]
   parameters:param
completionHandler:^(id responseObj, NSError *error) {
        U9ForumCategoryModel *model = [U9ForumCategoryModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
}


//发帖前获取发帖的游戏分类
+ (void)uploadImageWithUserid:(NSString *)userid andSession:(NSString *)session andGameID:(NSString *)gID andCompletionHandle:(void (^)(U9PostListModel *model, NSError *error))complete{
    NSString *param = [NSString stringWithFormat:@"userid=%@&sessionid=%@",userid,session];
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kUploadImg]
   parameters:param
completionHandler:^(id responseObj, NSError *error) {
        U9PostListModel *model = [U9PostListModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
}


//点赞
+ (void)onLikeWithUserid:(NSString *)userid andSession:(NSString *)session PostID:(NSString *)postID andCompletionHandle:(void (^)(U9MessageCommonModel *model, NSError *error))complete{
    NSString *param = [NSString stringWithFormat:@"userid=%@&sessionid=%@",userid,session];
    [self POSTBase64:[NSString stringWithFormat:@"%@%@?id=%@",Api_URL,kPostOnlike,postID]
   parameters:param
completionHandler:^(id responseObj, NSError *error) {
        U9MessageCommonModel *model = [U9MessageCommonModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
}



//取消点赞
+ (void)cancelLikeWithUserid:(NSString *)userid andSession:(NSString *)session PostID:(NSString *)postID andCompletionHandle:(void (^)(U9MessageCommonModel *model, NSError *error))complete{
    NSString *param = [NSString stringWithFormat:@"userid=%@&sessionid=%@",userid,session];
    [self POSTBase64:[NSString stringWithFormat:@"%@%@?id=%@",Api_URL,kPostCancellike,postID]
   parameters:param
completionHandler:^(id responseObj, NSError *error) {
        U9MessageCommonModel *model = [U9MessageCommonModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
}

@end
